package com.example.testhiber.initPackage.test.testmkdir;

import java.awt.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * java  打开某个特定的目录
 */
public class testEachFile {

    public static void main(String[] args) {

        try {
            //E:\testfile
            String initSrc = "D:"+File.separator+"testfile";
            File file = new File(initSrc);
            File[] fileList = file.listFiles();

            List<File> wjjList = new ArrayList<File>();//新建一个文件夹集合
            List<File> wjList = new ArrayList<File>();//新建一个文件集合
            getFile(fileList, wjjList, wjList);


        }catch (Exception e){
            System.out.println(e.getMessage());
        }

    }

    private static void getFile(File[] fileList, List<File> wjjList, List<File> wjList) {

        for (int i = 0; i < fileList.length; i++) {
            if (fileList[i].isDirectory()) {//判断是否为文件夹
                wjjList.add(fileList[i]);
            }else  if(fileList[i].isFile()){//判断是否为文件
                wjList.add(fileList[i]);
                for (File f:fileList) {
                    System.out.println(f.getName());
                }
                System.out.println();
            }
        }

    }
}
